package com.sdo.bambooksdk;

import java.io.File;

public class RestoreAllPrivateBook {

    static int currentProgress = 0;
    static String backupPath = "D:\\tempsnb\\";
    static int result = 0;

    public static void main(String args[]) {
        int hConn = BBUtil.getConn();
        TransCallback pCallbackFunc = new TransCallback() {

            public void invoke(int status, int progress, int userData) {
                currentProgress = progress;
            }
        };
        File dir = new File(backupPath);
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            String filename = children[i];
            if (filename.indexOf(".snb") > 0) {
                System.out.println(filename);
                result = BambookCore.INSTANCE.BambookVerifySnbFile(backupPath + filename);
                if (result == Const.BR_SUCC) {
                    result = BambookCore.INSTANCE.BambookReplacePrivBook(hConn, backupPath + filename, filename, pCallbackFunc, 0);
                    while (currentProgress < 100) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ex) {
                        }
                    }
                }
                currentProgress = 0;
            }
        }
        BambookCore.INSTANCE.BambookDisconnect(hConn);
    }
}
